package com.mu.controller;

import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.mu.entity.Record;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mu.common.Constants;
import com.mu.common.Result;
import com.mu.controller.dto.RecordDTO;
import com.mu.entity.*;
import com.mu.mapper.*;
import com.mu.service.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mu
 * @since 2022-10-21
 */
@RestController
@RequestMapping("/records")
public class RecordsController {
    //2023学年成绩表
    @Resource
    private Records2023Service records2023Service;
    @Resource
    private Records2023Mapper records2023Mapper;

    //2022学年成绩表
    @Resource
    private RecordsService recordsService;
    @Resource
    private RecordsMapper recordsMapper;

    //2021年成绩表
    @Resource
    private Records2021Service records2021Service;
    @Resource
    private Records2021Mapper records2021Mapper;

    //2019年
    @Resource
    private Records2019Service records2019Service;
    @Resource
    private Records2019Mapper records2019Mapper;

    //2020年
    @Resource
    private Records2020Service records2020Service;
    @Resource
    private Records2020Mapper records2020Mapper;

    //2024年
    @Resource
    private Records2024Service records2024Service;
    @Resource
    private Records2024Mapper records2024Mapper;

    //2025年
    @Resource
    private Records2025Service records2025Service;
    @Resource
    private Records2025Mapper records2025Mapper;

    //2026年
    @Resource
    private Records2026Service records2026Service;
    @Resource
    private Records2026Mapper records2026Mapper;

    //2027年
    @Resource
    private Records2027Service records2027Service;
    @Resource
    private Records2027Mapper records2027Mapper;

    //2028年
    @Resource
    private Records2028Service records2028Service;
    @Resource
    private Records2028Mapper records2028Mapper;

    //2029年
    @Resource
    private Records2029Service records2029Service;
    @Resource
    private Records2029Mapper records2029Mapper;

    //2030年
    @Resource
    private Records2030Service records2030Service;
    @Resource
    private Records2030Mapper records2030Mapper;

    //2031年
    @Resource
    private Records2031Service records2031Service;
    @Resource
    private Records2031Mapper records2031Mapper;

    //2032年
    @Resource
    private Records2032Service records2032Service;
    @Resource
    private Records2032Mapper records2032Mapper;

    @RequiresRoles("管理员")
    @PostMapping("/save")
    public Result save(@RequestBody RecordDTO recorddto) {
        if ("2022".equals(recorddto.getSchoolYear())) {
            Record record = new Record();
            BeanUtil.copyProperties(recorddto,record,true);
            return Result.success(recordsService.saveOrUpd(record));
        } else if ("2021".equals(recorddto.getSchoolYear())) {
            Record2021 record2021 = new Record2021();
            BeanUtil.copyProperties(recorddto, record2021,true);
            return Result.success(records2021Service.saveOrUpd(record2021));
        } else if ("2019".equals(recorddto.getSchoolYear())) {
            Record2019 record2019 = new Record2019();
            BeanUtil.copyProperties(recorddto, record2019,true);
            return Result.success(records2019Service.saveOrUpd(record2019));
        } else if ("2023".equals(recorddto.getSchoolYear())) {
            Record2023 record2023 = new Record2023();
            BeanUtil.copyProperties(recorddto, record2023,true);
            return Result.success(records2023Service.saveOrUpd(record2023));
        } else if ("2024".equals(recorddto.getSchoolYear())) {
            Record2024 record2024 = new Record2024();
            BeanUtil.copyProperties(recorddto, record2024,true);
            return Result.success(records2024Service.saveOrUpd(record2024));
        } else if ("2025".equals(recorddto.getSchoolYear())) {
            Record2025 record2025 = new Record2025();
            BeanUtil.copyProperties(recorddto, record2025,true);
            return Result.success(records2025Service.saveOrUpd(record2025));
        } else if ("2026".equals(recorddto.getSchoolYear())) {
            Record2026 record2026 = new Record2026();
            BeanUtil.copyProperties(recorddto, record2026,true);
            return Result.success(records2026Service.saveOrUpd(record2026));
        } else if ("2027".equals(recorddto.getSchoolYear())) {
            Record2027 record2027 = new Record2027();
            BeanUtil.copyProperties(recorddto, record2027,true);
            return Result.success(records2027Service.saveOrUpd(record2027));
        } else if ("2028".equals(recorddto.getSchoolYear())) {
            Record2028 record2028 = new Record2028();
            BeanUtil.copyProperties(recorddto, record2028,true);
            return Result.success(records2028Service.saveOrUpd(record2028));
        } else if ("2029".equals(recorddto.getSchoolYear())) {
            Record2029 record2029= new Record2029();
            BeanUtil.copyProperties(recorddto, record2029,true);
            return Result.success(records2029Service.saveOrUpd(record2029));
        } else if ("2030".equals(recorddto.getSchoolYear())) {
            Record2030 record2030 = new Record2030();
            BeanUtil.copyProperties(recorddto, record2030,true);
            return Result.success(records2030Service.saveOrUpd(record2030));
        } else if ("2031".equals(recorddto.getSchoolYear())) {
            Record2031 record2031 = new Record2031();
            BeanUtil.copyProperties(recorddto, record2031,true);
            return Result.success(records2031Service.saveOrUpd(record2031));
        } else if ("2032".equals(recorddto.getSchoolYear())) {
            Record2032 record2032 = new Record2032();
            BeanUtil.copyProperties(recorddto, record2032,true);
            return Result.success(records2032Service.saveOrUpd(record2032));
        }  else {
            return new Result(Constants.CODE_500,"参数错误",null);
        }
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        return Result.success(recordsService.removeById(id));
    }

    /**
     * 删除单挑记录
     * @param recorddto
     * @return
     */
    @RequiresRoles("管理员")
    @DeleteMapping("/del")
    public Result delete(@RequestBody RecordDTO recorddto) {
        if ("2022".equals(recorddto.getSchoolYear())) {
            QueryWrapper<Record> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record findOne = recordsService.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(recordsService.removeById(findOne.getId()));
            }
        } else if ("2021".equals(recorddto.getSchoolYear())) {
            QueryWrapper<Record2021> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record2021 findOne = records2021Service.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(records2021Service.removeById(findOne.getId()));
            }
        } else if ("2023".equals(recorddto.getSchoolYear())) {
            QueryWrapper<Record2023> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record2023 findOne = records2023Service.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(records2023Service.removeById(findOne.getId()));
            }
        } else if ("2019".equals(recorddto.getSchoolYear())){
            QueryWrapper<Record2019> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record2019 findOne = records2019Service.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(records2019Service.removeById(findOne.getId()));
            }
        } else if ("2020".equals(recorddto.getSchoolYear())){
            QueryWrapper<Record2020> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record2020 findOne = records2020Service.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(records2020Service.removeById(findOne.getId()));
            }
        } else if ("2024".equals(recorddto.getSchoolYear())){
            QueryWrapper<Record2024> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record2024 findOne = records2024Service.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(records2024Service.removeById(findOne.getId()));
            }
        } else if ("2025".equals(recorddto.getSchoolYear())){
            QueryWrapper<Record2025> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record2025 findOne = records2025Service.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(records2025Service.removeById(findOne.getId()));
            }
        } else if ("2026".equals(recorddto.getSchoolYear())){
            QueryWrapper<Record2026> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record2026 findOne = records2026Service.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(records2026Service.removeById(findOne.getId()));
            }
        } else if ("2027".equals(recorddto.getSchoolYear())){
            QueryWrapper<Record2027> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record2027 findOne = records2027Service.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(records2027Service.removeById(findOne.getId()));
            }
        } else if ("2028".equals(recorddto.getSchoolYear())){
            QueryWrapper<Record2028> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record2028 findOne = records2028Service.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(records2028Service.removeById(findOne.getId()));
            }
        } else if ("2029".equals(recorddto.getSchoolYear())){
            QueryWrapper<Record2029> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record2029 findOne = records2029Service.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(records2029Service.removeById(findOne.getId()));
            }
        } else if ("2030".equals(recorddto.getSchoolYear())){
            QueryWrapper<Record2030> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record2030 findOne = records2030Service.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(records2030Service.removeById(findOne.getId()));
            }
        } else if ("2031".equals(recorddto.getSchoolYear())){
            QueryWrapper<Record2031> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record2031 findOne = records2031Service.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(records2031Service.removeById(findOne.getId()));
            }
        } else if ("2032".equals(recorddto.getSchoolYear())){
            QueryWrapper<Record2032> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("学籍号", recorddto.getAccount());
            Record2032 findOne = records2032Service.getOne(queryWrapper);
            if (findOne != null) {
                return Result.success(records2032Service.removeById(findOne.getId()));
            }
        } else {
            return new Result(Constants.CODE_500,"参数错误",null);
        }
        return Result.success("成功");
    }

    @RequiresRoles("管理员")
    @PostMapping("/del/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        return Result.success(recordsService.removeByIds(ids));
    }

    @RequiresRoles(value = "管理员")
    @GetMapping
    public Result findAll() {
        return Result.success(recordsService.list());
    }

    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(recordsService.getById(id));
    }

    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
    @RequestParam Integer pageSize) {
        return Result.success(recordsService.page(new Page<>(pageNum, pageSize)));
    }

    /**
     * 根据学工号查询体侧成绩
     * @param account
     * @return
     */
    @RequiresRoles(value = {"管理员","学生"},logical = Logical.OR)
    @GetMapping("/account")
    public Result findOneRecordsByAccount(@RequestParam("account") String account,@RequestParam("schoolYear") String schoolYear) {
        Map<String,Object> map = new HashMap<>();
        if ("2022".equals(schoolYear)) {
            Record record = recordsService.getByAccount(account);
            map.put("学年","2022");
            map.put("data",record);
            return Result.success(map);
        } else if ("2021".equals(schoolYear)) {
            Record2021 record = records2021Service.getByAccount(account);
            map.put("学年","2021");
            map.put("data",record);
            return Result.success(map);
        } else if ("2023".equals(schoolYear)) {
            Record2023 record = records2023Service.getByAccount(account);
            map.put("学年","2023");
            map.put("data",record);
            return Result.success(map);
        }  else if ("2019".equals(schoolYear)) {
            Record2019 record = records2019Service.getByAccount(account);
            map.put("学年","2019");
            map.put("data",record);
            return Result.success(map);
        } else if ("2020".equals(schoolYear)) {
            Record2020 record = records2020Service.getByAccount(account);
            map.put("学年","2020");
            map.put("data",record);
            return Result.success(map);
        } else if ("2024".equals(schoolYear)) {
            Record2024 record = records2024Service.getByAccount(account);
            map.put("学年","2024");
            map.put("data",record);
            return Result.success(map);
        } else if ("2025".equals(schoolYear)) {
            Record2025 record = records2025Service.getByAccount(account);
            map.put("学年","2025");
            map.put("data",record);
            return Result.success(map);
        } else if ("2026".equals(schoolYear)) {
            Record2026 record = records2026Service.getByAccount(account);
            map.put("学年","2026");
            map.put("data",record);
            return Result.success(map);
        } else if ("2027".equals(schoolYear)) {
            Record2027 record = records2027Service.getByAccount(account);
            map.put("学年","2027");
            map.put("data",record);
            return Result.success(map);
        } else if ("2028".equals(schoolYear)) {
            Record2028 record = records2028Service.getByAccount(account);
            map.put("学年","2028");
            map.put("data",record);
            return Result.success(map);
        } else if ("2029".equals(schoolYear)) {
            Record2029 record = records2029Service.getByAccount(account);
            map.put("学年","2029");
            map.put("data",record);
            return Result.success(map);
        } else if ("2030".equals(schoolYear)) {
            Record2030 record = records2030Service.getByAccount(account);
            map.put("学年","2030");
            map.put("data",record);
            return Result.success(map);
        } else if ("2031".equals(schoolYear)) {
            Record2031 record = records2031Service.getByAccount(account);
            map.put("学年","2031");
            map.put("data",record);
            return Result.success(map);
        } else if ("2032".equals(schoolYear)) {
            Record2032 record = records2032Service.getByAccount(account);
            map.put("学年","2032");
            map.put("data",record);
            return Result.success(map);
        }  else {
            return new Result(Constants.CODE_500,"参数错误",null);
        }
    }

    @GetMapping("/findRecords")
    public Result findOneYearRecords(@RequestParam("schoolYear") String schoolYear) {
        Map<String, Object> map = new HashMap<>();
        if ("2022".equals(schoolYear)) {
            List<Record> list = new ArrayList<>();
            list = recordsMapper.selectList(null);
            map.put("年份", "2022");
            map.put("data",list);
            return Result.success(map);
        } else if ("2021".equals(schoolYear)) {
            List<Record2021> list = new ArrayList<>();
            list = records2021Mapper.selectList(null);
            map.put("年份", "2021");
            map.put("data",list);
            return Result.success(map);
        }  else if ("2023".equals(schoolYear)) {
            List<Record2023> list = new ArrayList<>();
            list = records2023Mapper.selectList(null);
            map.put("年份", "2023");
            map.put("data",list);
            return Result.success(map);
        }  else if ("2019".equals(schoolYear)) {
            List<Record2019> list = new ArrayList<>();
            list = records2019Mapper.selectList(null);
            map.put("年份", "2019");
            map.put("data",list);
            return Result.success(map);
        }  else if ("2020".equals(schoolYear)) {
            List<Record2020> list = new ArrayList<>();
            list = records2020Mapper.selectList(null);
            map.put("年份", "2020");
            map.put("data",list);
            return Result.success(map);
        }  else if ("2024".equals(schoolYear)) {
            List<Record2024> list = new ArrayList<>();
            list = records2024Mapper.selectList(null);
            map.put("年份", "2024");
            map.put("data",list);
            return Result.success(map);
        }  else if ("2025".equals(schoolYear)) {
            List<Record2025> list = new ArrayList<>();
            list = records2025Mapper.selectList(null);
            map.put("年份", "2025");
            map.put("data",list);
            return Result.success(map);
        }  else if ("2026".equals(schoolYear)) {
            List<Record2026> list = new ArrayList<>();
            list = records2026Mapper.selectList(null);
            map.put("年份", "2026");
            map.put("data",list);
            return Result.success(map);
        }  else if ("2027".equals(schoolYear)) {
            List<Record2027> list = new ArrayList<>();
            list = records2027Mapper.selectList(null);
            map.put("年份", "2027");
            map.put("data",list);
            return Result.success(map);
        }  else if ("2028".equals(schoolYear)) {
            List<Record2028> list = new ArrayList<>();
            list = records2028Mapper.selectList(null);
            map.put("年份", "2028");
            map.put("data",list);
            return Result.success(map);
        }  else if ("2029".equals(schoolYear)) {
            List<Record2029> list = new ArrayList<>();
            list = records2029Mapper.selectList(null);
            map.put("年份", "2029");
            map.put("data",list);
            return Result.success(map);
        }  else if ("2030".equals(schoolYear)) {
            List<Record2030> list = new ArrayList<>();
            list = records2030Mapper.selectList(null);
            map.put("年份", "2030");
            map.put("data",list);
            return Result.success(map);
        }  else if ("2031".equals(schoolYear)) {
            List<Record2031> list = new ArrayList<>();
            list = records2031Mapper.selectList(null);
            map.put("年份", "2031");
            map.put("data",list);
            return Result.success(map);
        }  else if ("2032".equals(schoolYear)) {
            List<Record2032> list = new ArrayList<>();
            list = records2032Mapper.selectList(null);
            map.put("年份", "2032");
            map.put("data",list);
            return Result.success(map);
        }  else {
            return new Result(Constants.CODE_500,"参数错误",null);
        }
    }


    @Resource
    private DataSourceTransactionManager metaTransactionManager;

    /**
     * 传入excel表格导入并更新数据
     * @param file
     * @return
     * @throws IOException
     */
    @RequiresRoles("管理员")
    @PostMapping("/import")
    public Result imp(MultipartFile file, String schoolYear) throws IOException {
        if ("2022".equals(schoolYear)) {
            recordsService.imp(file, schoolYear);
        } else if ("2021".equals(schoolYear)) {
            records2021Service.imp(file, schoolYear);
        } else if ("2023".equals(schoolYear)) {
            records2023Service.imp(file, schoolYear);
        } else if ("2019".equals(schoolYear)) {
            records2019Service.imp(file, schoolYear);
        } else if ("2020".equals(schoolYear)) {
            records2020Service.imp(file, schoolYear);
        } else if ("2024".equals(schoolYear)) {
            records2024Service.imp(file, schoolYear);
        } else if ("2025".equals(schoolYear)) {
            records2025Service.imp(file, schoolYear);
        } else if ("2026".equals(schoolYear)) {
            records2026Service.imp(file, schoolYear);
        } else if ("2027".equals(schoolYear)) {
            records2027Service.imp(file, schoolYear);
        } else if ("2028".equals(schoolYear)) {
            records2028Service.imp(file, schoolYear);
        } else if ("2029".equals(schoolYear)) {
            records2029Service.imp(file, schoolYear);
        } else if ("2030".equals(schoolYear)) {
            records2030Service.imp(file, schoolYear);
        } else if ("2031".equals(schoolYear)) {
            records2031Service.imp(file, schoolYear);
        } else if ("2032".equals(schoolYear)) {
            records2032Service.imp(file, schoolYear);
        }
        return Result.success(true);
    }

    /**
     * 导出接口
     */
    @GetMapping("/export")
    public Result export(@RequestParam("schoolYear") String schoolYear, HttpServletResponse response) throws IOException {
        //在内存操作，写出到浏览器
        ExcelWriter writer = ExcelUtil.getWriter(true);
        //自定义标题别名
        writer.addHeaderAlias("id", "序号");
        writer.addHeaderAlias("college", "学院");
        writer.addHeaderAlias("cls", "班级");
        writer.addHeaderAlias("account","学籍号" );
        writer.addHeaderAlias("name","姓名");
        writer.addHeaderAlias("sex", "身高");
        writer.addHeaderAlias("height", "身高");
        writer.addHeaderAlias("weight", "体重");
        writer.addHeaderAlias("heightAndWeightScore", "身高体重分数");
        writer.addHeaderAlias("heightAndWeightLevel", "身高体重等级");
        writer.addHeaderAlias("vitalCapacity", "肺活量");
        writer.addHeaderAlias("vitalCapacityBodyMassScore", "肺活量体重分数");
        writer.addHeaderAlias("vitalCapacityWeightLevel", "肺活量体重等级");
        writer.addHeaderAlias("fiftyRun", "50米跑");
        writer.addHeaderAlias("fiftyRunScore", "50米跑分数");
        writer.addHeaderAlias("fiftyRunLevel", "50米跑等级");
        writer.addHeaderAlias("thousandRun", "1000或800米跑");
        writer.addHeaderAlias("thousandRunScore", "1000或800米跑分数");
        writer.addHeaderAlias("thousandRunLevel", "1000或800米跑等级");
        writer.addHeaderAlias("sittingForwardFlexion", "坐位体前屈");
        writer.addHeaderAlias("sittingForwardFlexionScore", "坐位体前屈分数");
        writer.addHeaderAlias("sittingForwardFlexionLevel", "坐位体前屈等级");
        writer.addHeaderAlias("standingLongJump", "立定跳远");
        writer.addHeaderAlias("standingLongJumpScore", "立定跳远分数");
        writer.addHeaderAlias("standingLongJumpLevel", "立定跳远等级");
        writer.addHeaderAlias("pullUpOrOneMinuteSitUps", "引体向上或一分钟仰卧起坐");
        writer.addHeaderAlias("pullUpOrOneMinuteSitUpsScore", "引体向上或一分钟仰卧起坐分数");
        writer.addHeaderAlias("pullUpOrOneMinuteSitUpsLevel", "引体向上或一分钟仰卧起坐等级");
        writer.addHeaderAlias("totalTestScore", "测试总分");
        writer.addHeaderAlias("totalTestLevel", "总分等级");
        //从数据库查询所有数据
        if ("2022".equals(schoolYear)) {
            List<Record> list = recordsService.list();
            //一次性写出list内的对象到excel使用默认样式
            writer.write(list,true);
            // 设置浏览器响应的格式
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
            String fileName = URLEncoder.encode("2022体侧成绩信息", "UTF-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
        } else if ("2021".equals(schoolYear)) {
            List<Record2021> list = records2021Service.list();
            //一次性写出list内的对象到excel使用默认样式
            writer.write(list,true);
            // 设置浏览器响应的格式
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
            String fileName = URLEncoder.encode("2021体侧成绩信息", "UTF-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
        } else if ("2023".equals(schoolYear)) {
            List<Record2023> list = records2023Service.list();
            //一次性写出list内的对象到excel使用默认样式
            writer.write(list,true);
            // 设置浏览器响应的格式
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
            String fileName = URLEncoder.encode("2023体侧成绩信息", "UTF-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
        } else if ("2019".equals(schoolYear)) {
            List<Record2019> list = records2019Service.list();
            //一次性写出list内的对象到excel使用默认样式
            writer.write(list,true);
            // 设置浏览器响应的格式
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
            String fileName = URLEncoder.encode("2019体侧成绩信息", "UTF-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
        } else if ("2020".equals(schoolYear)) {
            List<Record2020> list = records2020Service.list();
            //一次性写出list内的对象到excel使用默认样式
            writer.write(list,true);
            // 设置浏览器响应的格式
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
            String fileName = URLEncoder.encode("2020体侧成绩信息", "UTF-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
        }

        //通过工具类创建writer写出到磁盘路径
//        ExcelWriter writer = ExcelUtil.getWriter(filesUploadPath+"/用户信息.xlsx");






        //获取输出流
        ServletOutputStream out = response.getOutputStream();
        writer.flush(out,true);
        out.close();
        writer.close();
        return Result.success(true);
    }


}

